package com.azt.front.action.coin;

import com.azt.api.pojo.CoinRecord;
import com.azt.api.pojo.CoinRule;
import com.azt.api.pojo.Company;
import com.azt.api.service.CoinService;
import com.azt.front.action.BaseAction;
import com.azt.front.permission.RequireCompany;
import com.azt.front.utils.ContextUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/coin")
@RequireCompany
public class CoinAction extends BaseAction {
		
	@Autowired
	private CoinService coinService;

	/**
	 * 我的安装币
	 * */
	@RequestMapping("/my")
	public String myCoin(ModelMap map) {
		Company company=ContextUtil.getCompany();
		int coinamount=coinService.getCoinByCompanyId(company.getId());
		map.addAttribute("coinamount", coinamount);
//		List<CoinRecord> recordList = coinService.findCoinRecord(company.getId());
		List<Map<String, Object>> coinRecord = coinService.getCoinRecord(company.getId());
		map.addAttribute("recordList", coinRecord);
		return"coin/mycoin";
	}

	/**
	 *
	 * */
	@RequestMapping("/qa")
	public String qa(ModelMap map) {
		Company company=ContextUtil.getCompany();
		int coinamount=coinService.getCoinByCompanyId(company.getId());
		map.addAttribute("coinamount", coinamount);
		List<CoinRule> getcoinList=coinService.findValidCoinRule();
		map.addAttribute("getcoinList", getcoinList);
		return"coin/qa";
	}

}
